<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div>
        <button onclick="notify()">点我查看</button>
    </div>
    <script>
//先检查浏览器是否支持
function notify(){
    if (!('Notification' in window)) {
        alert('你的浏览器不支持Notification')
    }
//检查是否拥有通知权限；有就通知，没有请求；
else if (Notification.permission=='granted') {
    var options={
        icon:'http://www.itechat.cn/ya8526/html/images/img10.jpg',
        body:'such a beautiful wolrld!'
    }
    var notification=new Notification('hello wolrld!',options);
}else if (Notification.permission !== 'denied'){
    Notification.requestPermission(
            function(permission){
                if (permission=='granted'){
                    var notification=new Notification('hello wolrld!');
                }
            }
        );
}
}
    </script>
</body>
</html>
